from celery import Celery
from django.core.mail import send_mail,settings
import time

app = Celery("celery_tasks.tasks", broker="redis://127.0.0.1:6379/4")


@app.task
def send_active_email(to_email, username,uname, token):
    """发送用户激活邮件"""
    subject = "天天生鲜欢迎你"  # 邮件标题    
    message = ''  # 邮件正文
    sender = settings.EMAIL_FROM  # 发件人
    receiver = [to_email]  # 收件人
    html_message = """                      
        <h1>欢迎您：%s</h1><br/>
        <h2>您正在为您的账号%s进行激活验证</h2><br/>
        <h3>请您在1小时内点击以下 链接进行账户激活</h3>
        <a href="http://127.0.0.1:8000/active/%s">http://127.0.0.1:8000/active/%s</a >
        """ % (username,uname,token, token)
    send_mail(subject, message, sender, receiver, html_message=html_message)